const short HEIGHT = 240;
const short WIDTH = 320;
const short MAX_AI_SPEED = 2;

const short BallSprite[6][6] = {
{0, 0, 1, 1, 0, 0},
{0, 1, 1, 1, 1, 0},
{1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1},
{0, 1, 1, 1, 1, 0},
{0, 0, 1, 1, 0, 0}
};

const short PlayerSprite[5][27] = {
{1,1,1,0,0,1,0,0,0,0,1,1,0,0,1,0,1,0,1,1,1,1,0,1,1,1,0,},
{1,0,0,1,0,1,0,0,0,1,0,0,1,0,1,0,1,0,1,0,0,0,0,1,0,0,1,},
{1,1,1,0,0,1,0,0,0,1,1,1,1,0,0,1,0,0,1,1,1,0,0,1,1,1,0,},
{1,0,0,0,0,1,0,0,0,1,0,0,1,0,0,1,0,0,1,0,0,0,0,1,0,1,0,},
{1,0,0,0,0,1,1,1,0,1,0,0,1,0,0,1,0,0,1,1,1,1,0,1,0,0,1,}
};

const short AISprite[5][8] = {
{0,1,1,0,0,1,1,1},
{1,0,0,1,0,0,1,0},
{1,1,1,1,0,0,1,0},
{1,0,0,1,0,0,1,0},
{1,0,0,1,0,1,1,1}
};

const short WonSprite[5][15] = {
  {1,0,0,0,1,0,0,1,1,0,0,1,0,0,1},
  {1,0,0,0,1,0,1,0,0,1,0,1,1,0,1},
  {1,0,1,0,1,0,1,0,0,1,0,1,0,1,1},
  {1,0,1,0,1,0,1,0,0,1,0,1,0,1,1},
  {0,1,0,1,0,0,0,1,1,1,0,1,0,0,1}
};


const short Numbers[50][4] = {
  {0, 1, 1 ,0},
  {1, 0, 0, 1},
  {1, 0, 0, 1},
  {1, 0, 0, 1},
  {0, 1, 1, 0},

  {0, 0, 1 ,0},
  {0, 1, 1, 0},
  {0, 0, 1, 0},
  {0, 0, 1, 0},
  {0, 0, 1, 0},

  {0, 1, 1 ,0},
  {1, 0, 0, 1},
  {0, 0, 1, 0},
  {0, 1, 0, 0},
  {1, 1, 1, 1},

  {0, 1, 1 ,0},
  {0, 0, 0, 1},
  {0, 0, 1, 0},
  {0, 0, 0, 1},
  {0, 1, 1, 0},

  {0, 1, 0 ,1},
  {1, 0, 0, 1},
  {1, 1, 1, 1},
  {0, 0, 0, 1},
  {0, 0, 0, 1},

  {1, 1, 1 ,1},
  {1, 0, 0, 0},
  {1, 1, 1, 0},
  {0, 0, 0, 1},
  {1, 1, 1, 0},

  {0, 1, 1 ,0},
  {1, 0, 0, 0},
  {1, 1, 1, 0},
  {1, 0, 0, 1},
  {0, 1, 1, 0},

  {1, 1, 1 ,1},
  {0, 0, 0, 1},
  {0, 0, 1, 0},
  {0, 0, 1, 0},
  {0, 0, 1, 0},

  {0, 1, 1 ,0},
  {1, 0, 0, 1},
  {0, 1, 1, 0},
  {1, 0, 0, 1},
  {0, 1, 1, 0},

  {0, 1, 1 ,0},
  {1, 0, 0, 1},
  {0, 1, 1, 1},
  {0, 0, 0, 1},
  {1, 1, 1, 0}
};

typedef struct
{
  short posX;
  short posY;
  short lastPosX;
  short lastPosY;
  short width;
  short height;
  short speedX;
  short speedY;
}Entity;

void DrawBall(Entity *ball, short isErasing);
void DrawPaddle(Entity *paddle, short isErasing);
void DrawPixel(short x, short y, short isBlack);
void RectUpdateBB(Entity *entity);
char GetPixel(short x, short y);
void FlushBackBuffer();
void RPaddleAI();
void DrawNumber(short x, short y, short num);
void Update();
void EraseDraw();
void Draw();
void BusyWait();
void SetLeds(int num);
int OpenDriver();
int ReadButtons();
